<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>学生信息管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../static/lib/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<ul class="layui-nav layui-bg-green">
    <li class="layui-nav-item "><a href="/teacherIndex">个人信息</a></li>
    <li class="layui-nav-item layui-this"><a href="/studentInfo" id="stu_lesson">学生成绩录入</a></li>
    <li class="layui-nav-item " id="stu_score"><a href="/teacherScore">学生成绩查询</a></li>

    <li class="layui-nav-item"><a href="/teacherMore">更多操作</a></li>
</ul>
<div class="layui-form">
    <table class="layui-table">
        <colgroup>
            <col width="150">
            <col width="150">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>学号</th>
            <th>姓名</th>
            <th>课程</th>
            <th>成绩</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {% for student in students %}
            <tr>
                <td >{{ student.id }}</td>
                <td>{{ student.name }}</td>
                <td id="lessonName">{{ student.lesson }}</td>
                <td><input type="text" placeholder="录入该学生的成绩" id="{{ student.id }}"></td>
                <td id="status">{{ student.status }}</td>
                <td>
                    <button type="button" class="layui-btn layui-btn-sm" onclick="updateScore(this)" name="{{ student.id }}" lessonName="{{ student.lesson }}" >上传</button>
                </td>

            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>
<div id="demo3"></div>
<script src="../static/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="../static/jquerymini.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['element', 'table'], function () {
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

        //监听导航点击
        element.on('nav(demo)', function (elem) {
            //console.log(elem)
            layer.msg(elem.text());
        });


    });

    function updateScore(e) {
        id = $(e).attr("name")
        lessonName =$(e).attr("lessonName")
        sc = document.getElementById(id).value;

        {#var httpRequest = new XMLHttpRequest();//第一步：建立所需的对象#}
        {#httpRequest.open('GET', '/updateScore?sc=sc&stuId=id&lessonName=lessonName', true);//第二步：打开连接  将请求参数写在url中  ps:"./Ptest.php?name=test&nameone=testone"#}
        {#httpRequest.send();//第三步：发送请求  将请求参数写在URL中#}
        $.ajax(
            {
                url: '/updateScore/',
                method: 'post',
                data: {'sc': sc, 'stuId': id, 'lessonName': lessonName},
                dataType: 'JSON',
                'async' : false

            }
        );
        location.reload()
    }

</script>

</body>
</html>